﻿package {
    import flash.display.MovieClip;
	import flash.events.Event;
	public class Player extends MovieClip
	{
		var HP:Number = 9;
		var lvl:Number = 0;
		var statPt:Number = 5;
		var currentExp:Number = 0;
		var expNeeded:Number;
		//Substats
		var maxHP:Number;
		var atk:Number;
		var atkspd:Number;
		var movement:Number;
		var def:Number;
		var jump:Number = 20;
		//Basic Stats
		var str:Number = 1;
		var agi:Number = 1;
		var vit:Number = 1;
		var dex:Number = 1;
		//Usage for physics
		var dy:Number = 0;
		public function Player()
		{
			calculateHP();
			HP = maxHP;
			calculateAtk();
			calculateAtkspd();
			calculateMovement();
			calculateDef();
			calculateExpNeeded();
		}
		public function getHP():Number
		{
			return HP;
		}
		public function getMaxHP():Number
		{
			return maxHP;
		}
		public function getlvl():Number
		{
			return lvl;
		}
		public function getStatPoints():Number
		{
			return statPt;
		}
		public function getStr():Number
		{
			return str;
		}
		public function getAgi():Number
		{
			return agi;
		}
		public function getVit():Number
		{
			return vit;
		}
		public function getDex():Number
		{
			return dex;
		}
		public function getCurrentExp():Number
		{
			return currentExp;
		}
		public function getExpNeeded():Number
		{
			return expNeeded;
		}
		public function getAtk():Number
		{
			return atk;
		}
		public function getAtkSpd():Number
		{
			return atkspd;
		}
		public function getMovement():Number
		{
			return movement;
		}
		public function getDef():Number
		{
			return def;
		}
		public function getJump():Number
		{
			return jump;
		}
		public function decreaseStat():void
		{
			statPt--;
		}
		public function increaseStr():void
		{
			str++;
		}
		public function increaseAgi():void
		{
			agi++;
		}
		public function increaseVit():void
		{
			vit++;
		}
		public function increaseDex():void
		{
			dex++;
		}
		//Sets hp of player, if dead, return false
		public function setHP(hp:Number):Boolean
		{
			if(hp <= 0)
			{
				HP = 0;
				return false;
			}
			else
			{
				HP = hp;
				return true;
			}
		}
		public function calculateAtk():void
		{
			atk = str + (.25*dex);
		}
		public function calculateAtkspd():void
		{
			atkspd = dex + (.1*agi);
		}
		public function calculateMovement():void
		{
			movement = agi;
		}
		public function calculateHP():void
		{
			maxHP = vit + 10;
		}
		public function calculateDef():void
		{
			def = (.5*vit);
		}
		public function calculateExpNeeded():void
		{
			//Base exp + 1.5^lvl + random (1-50)
			expNeeded = Math.ceil(25 + Math.pow(1.5,lvl) + Math.random()*50);
		}
		public function playerGravity(gravity:Number)
		{
			dy+=gravity;
			if(dy>10)
			{
				dy = 10;
			}
		}
		public function doesJump(jumpFactor:Number)
		{
			dy = -jumpFactor;
		}
		public function resetFallRate():void
		{
			dy = 0;
		}
		public function getFallRate():Number
		{
			return dy;
		}
		public function lvlUp():void
		{
			lvl++;
			currentExp = 0;
			calculateExpNeeded();
			updateStats();
		}
		public function updateStats():void
		{
			calculateHP();
			calculateAtk();
			calculateAtkspd();
			calculateMovement();
			calculateDef();
		}
	}
}